package br.com.felix.easyclearcase.tasks;

import br.com.felix.easyclearcase.tasks.Task.TaskStatus;


/**
 * Base class for a TaskStatusListener that does something only when the task
 * has changed its status to either CANCELLED, COMPLETED (success or fail).
 * @see TaskStatusListener
 * */
public abstract class TaskCompletedStatusListener extends TaskStatusListener{

	
	private boolean afterTaskExecuted = false;
	/**
	 * @see TaskStatusListener#statusChanged(TaskStatus, TaskStatus)
	 * */
	@Override
	public void statusChanged(TaskStatus oldValue, TaskStatus newValue) {
		switch(newValue){
			case CANCELLED:
			case COMPLETE_FAIL:
			case COMPLETE_SUCCESS:
				if(!afterTaskExecuted){
					afterTaskExecuted = true;
					doAfterTask(newValue);
				}
		}
	}
	
	/**
	 * Method called if the task has been cancelled or completed (success or fail).
	 * */
	public abstract void doAfterTask(TaskStatus e);
	
}
